#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;
using ll = long long;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int V = 1e5;
const int mod = 1e9 + 7;

int n, b[N], f[N][2][2], a[N];

int upd(int x) { return x + (x >> 31 & mod); }

void solve() {
	n = in; rep(i, 1, n) a[i] = 0;
	rep(i, 2, n) b[i] = in, a[i - 1] = max(a[i - 1], b[i]), a[i] = max(a[i], b[i]);
	b[n + 1] = b[n]; b[1] = b[2];
	rep(i, 0, n) f[i][0][0] = f[i][0][1] = f[i][1][0] = f[i][1][1] = 0;
	f[1][1][1] = 1; f[1][0][0] = V - b[2];
	rep(i, 2, n) {
		rep(j, 0, 1) {
			rep(k, 0, 1) if(f[i - 1][j][k]) {
				rep(d, 0, 1) {
					rep(v, 0, 1) {
						if(b[i] == b[i + 1] && d != v) continue;
						if(b[i] != b[i + 1] && d && v) continue;
						if(k == 0 && d == 0) continue;
						if(d == 1 && a[i] > b[i]) continue;
						if(v == 1 && a[i] > b[i + 1]) continue;
						int cho; if(d | v) cho = 1; else cho = V - a[i];
						f[i][d][v] = upd(f[i][d][v] + 1ll * f[i - 1][j][k] * cho % mod - mod);
					}
				}
			}
		}
	}
	int ans = 0;
	rep(j, 0, 1) rep(k, 0, 1) {
		if(k == 1) ans = upd(ans + 1ll * f[n - 1][j][k] * (V - a[n] + 1) % mod - mod);
		else ans = upd(ans + f[n - 1][j][k] - mod);
	}
	cout << ans << endl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    int t = in; while(t--) solve();
}
